package com.elinkway.infinitemovies.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.SearchKeyWords;
import com.le123.ysdq.R;

public class HotSearchKeyGridAdapter extends MyBaseAdapter {

	private SearchKeyWords keywordList;

	private class KeywordHolder {
		TextView hotSearchRankTv;
		TextView hotSearchNameTv;
		View divider;
	}

	public HotSearchKeyGridAdapter(Context context, SearchKeyWords keywordList) {
		super(context);
		this.keywordList=keywordList;
	}

	@Override
	public int getCount() {
		return keywordList.getWords().size();
	}
	public void clear(){
		keywordList.getWords().clear();
		notifyDataSetChanged();
	}
	
	public void resetData(SearchKeyWords words) {
		keywordList = words;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		KeywordHolder holder = new KeywordHolder();
		if(convertView==null){
			convertView=inflater.inflate(R.layout.hot_searchkey_item_layout, null);
			holder.hotSearchRankTv = (TextView) convertView.findViewById(R.id.hot_rank_tv);
			holder.hotSearchNameTv = (TextView) convertView.findViewById(R.id.hot_name_tv);
			holder.divider = convertView.findViewById(R.id.divider);
			convertView.setTag(holder);
		}
		else{
			holder=(KeywordHolder) convertView.getTag();
		}
		if(position == 0){
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffff4338"));
		}else if(position == 1){
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffff8938"));
		}else if(position == 2){
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffffac38"));
		}else{
			holder.hotSearchRankTv.setBackgroundColor(Color.parseColor("#ffcccccc"));
		}
		holder.hotSearchRankTv.setText(position + 1 +"");
		holder.hotSearchNameTv.setText(keywordList.getWords().get(position));

		if (position == getCount() - 1 || position == getCount() - 2) {
			holder.divider.setVisibility(View.GONE);
		} else {
			holder.divider.setVisibility(View.VISIBLE);
		}
		return convertView;
	}

}
